package Mysqlcon;

import com.mysql.cj.MysqlConnection;

import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class Conn {
	public static Properties prop = new Properties();

	public static String url;
	public static String name;
	public static String user ;
	public static String password;
   	public static Connection connection =null;
	public static PreparedStatement prepareStatement =null;
    public static Statement sta=null;
  	public static ResultSet res=null;


	public Conn() {

		try {
			prop.load(Conn.class.getResourceAsStream("../config.properties"));
			//System.out.println("properties 文件加载成功！");
		} catch (IOException e) {
			e.printStackTrace();
		}
		url=prop.getProperty("url");
		name=prop.getProperty("name");
		user=prop.getProperty("user");
		password=prop.getProperty("password");

		try {
			Class.forName(name);
			try {
				connection= DriverManager.getConnection(url,user,password);
			} catch (SQLException throwable) {
				throwable.printStackTrace();
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}


	}

	public void select2(String sql)throws Exception{

			sta=connection.createStatement();
			res=sta.executeQuery(sql);
			while(res.next()){
				String string1=res.getString(1);
				String string2=res.getString(2);
				System.out.println(string1+string2);
			}
		}

}
